package com.bltec.emergency.common;

import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class AllExceptionHandler {
    @ExceptionHandler(UnauthorizedException.class)
    @ResponseBody
    //没有权限
    public ResponseJson handleShiroException(Exception ex) {
        return ResponseJson.NO_AUTHORIZE;
    }

    @ExceptionHandler(AuthorizationException.class)
    @ResponseBody
    //没有认证
    public ResponseJson authorizationException(Exception ex) {
        return ResponseJson.NO_AUTHORIZE;
    }

    @ExceptionHandler(NullPointerException.class)
    @ResponseBody
    //空指针
    public ResponseJson handleNullPointerException(Exception ex) {
        return new ResponseJson(Constant.FAIL, ex.getMessage());
    }
}